package com.webxiaohua.thread.threadlocal;

/**
 * @author shenxinhua
 * @date 2019-06-23 11:55
 * @desc xxx
 */
public class ThreadLocalTest implements Cloneable{
    public static void main(String... args){
        ThreadLocalTest p = new ThreadLocalTest();
        System.out.println(p);
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                ThreadLocal<ThreadLocalTest> threadLocal = new ThreadLocal<>();
                System.out.println(threadLocal);
                threadLocal.set(p);
                System.out.println(threadLocal.get());
                threadLocal.remove();
                try{
                    threadLocal.set((ThreadLocalTest) p.clone());
                    System.out.println(threadLocal.get());
                }catch (CloneNotSupportedException ex){
                    ex.printStackTrace();
                }
                System.out.println(threadLocal);
            }
        });
        t.start();
    }
}
